package com.yefu.springcloud.controller;

import com.yefu.springcloud.entities.CommonResult;
import com.yefu.springcloud.entities.Payment;
import com.yefu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort ;


    @PostMapping("/payment/create")
    public CommonResult create(@RequestBody Payment payment){
        int result = paymentService.create(payment);

        log.info("****插入结果为：" +result);

        if (result > 0){
            return new CommonResult(200,"插入成功,请求端口："+serverPort,result);
        }else {
            return new CommonResult(404,"插入失败",null);
        }
    }


    @GetMapping("/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable Long id){
        Payment payment = paymentService.getPaymentById(id);

        log.info("****获取结果为：" +payment+"你好java");

        System.out.println("这是获取操作");
        if (payment != null){
            return new CommonResult(200,"查询成功,请求端口："+serverPort,payment);
        }else {
            return new CommonResult(404,"查询失败",null);
        }
    }

    @PostMapping("/payment/update")
    public CommonResult updatePayment( @RequestBody Payment payment){
        int res = paymentService.updatePayment(payment);
        log.info("****获取结果为：" + res);

        if (res > 0){
            return new CommonResult(200,"修改成功,请求端口："+serverPort,res);
        }else {
            return new CommonResult(404,"修改失败",null);
        }
    }


}
